package org.jeecg.modules.flow.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.flow.entity.ActHiActInstance;
import org.jeecg.modules.flow.query.HistoryActivityQuery;
import org.jeecg.modules.flow.service.IActHiActInstanceService;
import org.jeecg.modules.flow.vo.HistoryActivityInstanceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: hi_actinst
 * @Author: jeecg-boot
 * @Date: 2021-12-29
 * @Version: V1.0
 */
@Api(tags = "历史流程活动环节API")
@RestController
@RequestMapping("/flow/actHiActInstance")
@Slf4j
public class ActHiActInstanceController extends JeecgController<ActHiActInstance, IActHiActInstanceService> {
    @Autowired
    private IActHiActInstanceService actHiActInstanceService;

    /**
     * 分页列表查询
     *
     * @param actHiActInstance
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "分页列表查询")
    @ApiOperation(value = "分页列表查询", notes = "分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(ActHiActInstance actHiActInstance,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<ActHiActInstance> queryWrapper = QueryGenerator.initQueryWrapper(actHiActInstance, req.getParameterMap());
        Page<ActHiActInstance> page = new Page<ActHiActInstance>(pageNo, pageSize);
        IPage<ActHiActInstance> pageList = actHiActInstanceService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "查询历史活动环节记录列表", notes = "可指定流程实例id、业务号来查询")
    @GetMapping(value = "/queryHistoricActivityInstance")
    public Result<Page<HistoryActivityInstanceVo>> queryHistoricActivityInstance(HistoryActivityQuery query
            , @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo
            , @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<HistoryActivityInstanceVo> page = actHiActInstanceService.queryHistoricActivityInstance(query, pageNo, pageSize);
        return Result.OK(page);
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        ActHiActInstance actHiActInstance = actHiActInstanceService.getById(id);
        if (actHiActInstance == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(actHiActInstance);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param actHiActInstance
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ActHiActInstance actHiActInstance) {
        return super.exportXls(request, actHiActInstance, ActHiActInstance.class, "hi_actinst");
    }


}
